<template>
  <div>
    <van-uploader :after-read="afterRead"/>

    <img :src="url" alt=""/>
  </div>
</template>
<script>

export default {

  data() {
    return {

      token: '',
      url: ''
    }
  },
  methods: {

    getToken() {
      this.axios.get('qntoken').then(res => {
        this.token = res.data.token
      })
    },
    afterRead(file) {
      // 此时可以自行将文件上传至服务器
      console.log(file);
      var formdata = new FormData()
      formdata.append('token', this.token)
      formdata.append('file', file.file)
      this.axios.post('http://up-z1.qiniu.com/', formdata).then(res => {
        console.log(res)
        this.url = 'http://r32a24zdm.hb-bkt.clouddn.com/' + res.data.key
      })
    },
  },
  mounted() {
    this.getToken()
  },
}
</script>
<style lang="">

</style>
